<template>
  <el-form
    :inline="true"
    :model="form"
    ref="form"
    size="mini"
    style="margin-bottom: -18px;">

    <el-form-item label="uuid" prop="uuid">
      <el-input
        v-model="form.uuid"
        placeholder="uuid"
        style="width: 120px;"/>
    </el-form-item>

    <el-form-item label="项目名称" prop="project_title">
      <el-input
        v-model="form.project_title"
        placeholder="项目名称"
        style="width: 100px;"/>
    </el-form-item>

    <el-form-item label="项目创建者" prop="project_creater">
      <el-input
        v-model="form.project_creater"
        placeholder="项目创建者"
        style="width: 100px;"/>
    </el-form-item>

    <el-form-item label="项目更新人" prop="project_updater">
      <el-input
        v-model="form.project_updater"
        placeholder="项目更新人"
        style="width: 100px;"/>
    </el-form-item>

    <el-form-item>
      <el-button
        type="primary"
        @click="handleFormSubmit">
        <d2-icon name="search"/>
        查询
      </el-button>
    </el-form-item>

    <el-form-item>
      <el-button
        @click="handleFormReset">
        <d2-icon name="refresh"/>
        重置
      </el-button>
    </el-form-item>

    <el-form-item>
      <el-button
        @click="add">
        <d2-icon name="plus-square-o"/>
        新增
      </el-button>
    </el-form-item>

    <el-form-item>
      <el-button
        @click="delAll">
        <d2-icon name="trash-o"/>
        删除
      </el-button>
    </el-form-item>

  </el-form>
</template>

<script>
export default {
  name: 'PageHeader',
  data () {
    return {
      form: {
        uuid: '',
        title: ''
      }
    }
  },
  methods: {
    add () {
      this.$emit('add')
    },
    delAll () {
      this.$emit('delAll')
    },
    handleFormSubmit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          for (let k in this.form) {
            if (this.form[k] === '') { // 排除空字符串、-、.
              delete this.form[k]// 删除对象属性
            }
          }
          this.$emit('submit', this.form)
        } else {
          this.$notify.error({
            title: '错误',
            message: '表单校验失败'
          })
          return false
        }
      })
    },
    handleFormReset () {
      this.$refs.form.resetFields()
    }
  }
}
</script>
